<style scoped src="./index.scss" lang="scss" rel="stylesheet/scss"></style>
<template src="./index.html"></template>
<script>
export default {
  mixins: [Vue.prototype.$vFN.Mixins.Base],
  data() {
    return {
      load: true,
      form: {
        // 商品附加信息
        appendLst: [],
        // 是否开启附加信息功能 0否 1是
        isOpenAppend: "",
        // 是否开启商品评论 0否 1是
        isOpenComment: "",
        // 评论是否隐藏 0否 1是
        isShowComment: "",
        // 自动评论内容
        autoCommentContent: "",
        // 自动评论天数
        autoCommentTime: "",
        id: "",
      },
      //  新增评论默认状态
      commentStatus: 1,

      apiUrl: {
        detail: "mall-site-portal/product-setting/getItem",
        save: "mall-site-portal/product-setting/saveOrUpdate",
      },
    };
  },
  methods: {
    init() {
      this.gitData();
    },

    // 验证
    validate() {
      return new Promise((resolve, reject) => {
        this.$refs["editForm"].validate((valid) => {
          valid ? resolve(true) : resolve(false);
        });
      });
    },

    // 验证天数
    validatorNumber(rule, value, callback){
    
       if (value != 0 &&  this.$vFN.Utils.isEmpty(value)) {
        callback(new Error("不能为空"));
      }  else {
        // 只能填正整数
        this.$vFN.Tools.validateStock(rule, value, callback);
      }

    },

    // 获取商品设置
    async gitData() {
      this.load = true;

      let _data = await this.$vFN.Http.post(
        {
          url: this.apiUrl.detail,
        },
        window
      );

      if (_data._ok) {
        for (let i in this.form) {
          let _d = _data.data[i];
          if (_d != null) {
            this.form[i] = _d;
          }
        }
      }

      this.load = false;
    },

    // 保存
    async submit() {

      if (!(await this.validate())) {
        return;
      }

      this.load = true;

      let _data = await this.$vFN.Http.post(
          {
            url: this.apiUrl.save,
            data: this.form,
          },
          window
        );

        if (_data._ok) {
          this.$vFN.Tools.messageSuccess("操作成功");
          this.init();
        }

      this.load = false;
    },
  },
  mounted() {
    this.init();
  },
};
</script>